//
//  SetTableViewCellT.m
//  EggSteward
//
//  Created by 王道林 on 16/9/8.
//  Copyright © 2016年 王道林. All rights reserved.
//

#import "SetTableViewCellT.h"
#import "Masonry.h"
@implementation SetTableViewCellT

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self createSubView];
    }
    return self;
}

- (void)createSubView
{
    _labelTitle = [[BaseLabel alloc] init];
    [self.contentView addSubview:_labelTitle];
    
    _switchDelete = [[BaseSwitch alloc] init];
    [self.contentView addSubview:_switchDelete];
    [_switchDelete addTarget:self action:@selector(switchAction:) forControlEvents:UIControlEventValueChanged];
}


- (void)layoutSubviews
{
    [super layoutSubviews];
    [_labelTitle mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.contentView.mas_left).mas_offset(15);
        make.top.mas_equalTo(self.contentView.mas_top).mas_offset(10);
        make.bottom.mas_equalTo(self.contentView.mas_bottom).mas_offset(-10);
        make.width.mas_equalTo(self.contentView.mas_width).multipliedBy(0.5);
    }];
    
    [_switchDelete mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(self.contentView.mas_right).mas_offset(-40);
        make.top.mas_equalTo(self.contentView.mas_top).mas_offset(15);
        make.bottom.mas_equalTo(self.contentView.mas_bottom).mas_offset(-15);
        make.width.mas_equalTo(30);
    }];
    
}

#pragma mark -switch 的活动

- (void)switchAction:(BaseSwitch *)switchDe
{
  
    if (switchDe.on == YES) {
        self.BlockOn(switchDe);
        [[NSNotificationCenter defaultCenter] postNotificationName:@"night" object:nil userInfo:nil];
        NSUserDefaults *userDefault = [NSUserDefaults standardUserDefaults];
        [userDefault removeObjectForKey:@"night"];
        [userDefault setBool:YES forKey:@"night"];
    } else
    {
        self.BlockOff(switchDe);
        [[NSNotificationCenter defaultCenter] postNotificationName:@"day" object:nil userInfo:nil];
        NSUserDefaults *userDefault = [NSUserDefaults standardUserDefaults];
        [userDefault removeObjectForKey:@"night"];
        [userDefault setBool:NO forKey:@"night"];
    }
}



@end
